package com.foreknow.demo16;

import com.foreknow.demo16.User;

import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
import java.util.TreeSet;

public class SetDemo {
    public static void main(String[] args) {
        User u1 = new User();
        u1.setName("fender");
        User u2 = new User();
        u2.setName("gibson");
        User u3 = new User();
        u3.setName("yamaha");
        //1.创建一个set集合
        //Set<User> set = new HashSet<>();
        Set<String> set = new TreeSet<>();
        //2.向集合中添加元素
        set.add("b");
        set.add("a");
        set.add("d");
        //3.通过迭代器遍历集合
        Iterator<String> it = set.iterator();
        while (it.hasNext()) {
            String u = it.next();
            System.out.println(u);
        }
    }
}
